package com.ruoyi.mall.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallGoodsClass;
import com.ruoyi.mall.service.IMallGoodsClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品类型Controller
 *
 * @author chang
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/mall/mallGoodsClass")
public class MallGoodsClassController extends BaseController
{
    @Autowired
    private IMallGoodsClassService mallGoodsClassService;

    /**
     * 查询商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallGoodsClass mallGoodsClass)
    {
        startPage();
        List<MallGoodsClass> list = mallGoodsClassService.selectMallGoodsClassList(mallGoodsClass);
        return getDataTable(list);
    }

    /**
     * 导出商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsClass:export')")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallGoodsClass mallGoodsClass)
    {
        List<MallGoodsClass> list = mallGoodsClassService.selectMallGoodsClassList(mallGoodsClass);
        ExcelUtil<MallGoodsClass> util = new ExcelUtil<MallGoodsClass>(MallGoodsClass.class);
        return util.exportExcel(list, "商品类型数据");
    }

    /**
     * 获取商品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsClass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallGoodsClassService.selectMallGoodsClassById(id));
    }

    /**
     * 新增商品类型
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsClass:add')")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallGoodsClass mallGoodsClass)
    {
        mallGoodsClass.setCreateAt(DateUtils.getTime());
        return toAjax(mallGoodsClassService.insertMallGoodsClass(mallGoodsClass));
    }

    /**
     * 修改商品类型
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsClass:edit')")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallGoodsClass mallGoodsClass)
    {
        return toAjax(mallGoodsClassService.updateMallGoodsClass(mallGoodsClass));
    }

    /**
     * 删除商品类型
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsClass:remove')")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallGoodsClassService.deleteMallGoodsClassByIds(ids));
    }

    @GetMapping("/getClassList")
    public AjaxResult getClassList(MallGoodsClass mallGoodsClass)
    {
        List<MallGoodsClass> list = mallGoodsClassService.selectMallGoodsClassList(mallGoodsClass);
        return AjaxResult.success(list);
    }
}
